/**************************************************************
 *@ProjectName: blweibo
 *@FileName: SearchSquareActivity.java
 *@Date: 2011-5-31
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo;

import java.util.ArrayList;
import java.util.HashSet;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

/**
 * The Class SearchSquareActivity.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-31
 */
public class SearchSquareActivity extends HomeListBaseActivity {

    /** The m list view. */
    private ListView mListView;

    /** The bt search. */
    private Button btSearch;

    /** The m search mode. */
    private int mSearchMode = 1;

    /** The m rb search user. */
    private RadioButton mRbSearchUser;

    /** The m rb search weibo. */
    private RadioButton mRbSearchWeibo;

    /** The keyword. */
    private String keyword;

    /** The m actv keyword. */
    private AutoCompleteTextView mActvKeyword;

    /*
     * (non-Javadoc)
     * 
     * @see com.yingnet.zhiweibo.BaseActivity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.searchsquare);
        setTitleBar(1, null, getString(R.string.menu_search), null);
        mActvKeyword = ((AutoCompleteTextView) findViewById(R.id.AutoCompleteTextView01));
        mActvKeyword.setAdapter(new ArrayAdapter(this, 17367050, new ArrayList(new HashSet())));
        btSearch = (Button) findViewById(R.id.btSearch);
        btSearch.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                keyword = mActvKeyword.getText().toString().trim();
                if (TextUtils.isEmpty(keyword)) {
                    Toast.makeText(SearchSquareActivity.this, "请输入关键字", Toast.LENGTH_SHORT).show();
                } else {
                    Intent localIntent = new Intent();
                    localIntent.setClass(SearchSquareActivity.this, SearchActivity.class);
                    localIntent.putExtra("searchFlag", mSearchMode);
                    localIntent.putExtra("keyword", keyword);
                    startActivityForResult(localIntent, 1);
                }
            }
        });
        mRbSearchUser = (RadioButton) findViewById(R.id.rbSearchUser);
        mRbSearchUser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton paramCompoundButton, boolean paramBoolean) {
                if (paramBoolean) {
                    mSearchMode = 0;
                }
            }
        });
        mRbSearchWeibo = (RadioButton) findViewById(R.id.rbSearchWeibo);
        mRbSearchWeibo.setChecked(true);
        mRbSearchWeibo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton paramCompoundButton, boolean paramBoolean) {
                if (paramBoolean) {
                    mSearchMode = 1;
                }
            }
        });

        mListView = (ListView) findViewById(R.id.LvSquare);
        mListView.setDivider(null);
        mListView.setAdapter(new SquareItemAdapter(this));
        mListView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(SearchSquareActivity.this, LookAroundListActivity.class));
            }
        });
    }

    /**
     * The Class SquareItemAdapter.
     * 
     * @author SunHaibin
     * @since Android 1.6
     * @history 2011-5-31
     */
    class SquareItemAdapter extends BaseAdapter {

        /** The context. */
        Context context;

        /** The tv name. */
        TextView tvName;

        /**
         * Instantiates a new square item adapter.
         * 
         * @param arg2
         *            the arg2
         */
        public SquareItemAdapter(Context arg2) {
            context = arg2;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getCount()
         */
        @Override
        public int getCount() {
            return 1;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getItem(int)
         */
        @Override
        public Object getItem(int paramInt) {
            return Integer.valueOf(paramInt);
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getItemId(int)
         */
        @Override
        public long getItemId(int paramInt) {
            return paramInt;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getView(int, android.view.View,
         * android.view.ViewGroup)
         */
        @Override
        public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
            View localView = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(
                    R.layout.square_item_view, null);
            tvName = (TextView) localView.findViewById(R.id.tvItemName);
            if (paramInt == 0) {
                tvName.setText(getString(R.string.link_lookaround));
            }
            return localView;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.yingnet.zhiweibo.HomeListBaseActivity#handleTitleBarEvent(int)
     */
    @Override
    protected void handleTitleBarEvent(int paramInt) {

    }
}